<template>
  <PageContainer>
    <view class="container">
      <Header title="合作申请" />
      <TResult
        types="success"
        title="合作申请已发送"
        content="合作申请发送成功，待对方秘书处审核"
        :cancel-text="contactsPhone ? '联系秘书处' : ''"
        confirm-text="查看合作详情"
        @cancel="cancel"
        @confirm="confirm"
      />
      <FixedCode />
    </view>
  </PageContainer>
</template>

<script lang="ts" setup>
  /* cooperationResult 合作申请结果 */
  import PageContainer from '@/components/PageContainer/index.vue';
  import Header from '@/components/Header/index.vue';
  import TResult from '@/components/TResult/index.vue';
  import FixedCode from '@/components/OfficialAccount/fixedCode.vue';
  import { onLoad, reLaunch, redirectTo } from '@/router';
  import { ref, unref } from 'vue';
  import { TabsListValueEnum } from '@/enums/cooperationEnum';

  const detailsIDS = ref<number[]>([]);
  const contactsPhone = ref<string>('');
  const type = ref<TabsListValueEnum>();

  onLoad<'cooperationResult'>((op) => {
    detailsIDS.value = op?.ids ?? [];
    contactsPhone.value = op?.phone ?? '';
    type.value = op.type;
  });

  const cancel = () => {
    uni.makePhoneCall({ phoneNumber: unref(contactsPhone) });
  };
  const confirm = () => {
    if (unref(detailsIDS).length) {
      if (type.value == TabsListValueEnum.QUICK_APLIST) {
        redirectTo({
          name: 'cooperationInvitationDetail',
          options: { id: unref(detailsIDS)[0] as number, type: type.value },
        });
      } else {
        redirectTo({
          name: 'cooperationDetails',
          options: { id: unref(detailsIDS)[0] as number, type: type.value },
        });
      }
    } else {
      reLaunch({ name: 'cooperationList' });
    }
  };
</script>

<style lang="scss" scoped></style>
